﻿//input输入框 弹起/收起 手机软键盘隐藏/显示底部菜单
function showHideMenu() {
    const clientHeight = $(window).height()
    $(window).on('resize', function () {
        const nowClientHeight = $(window).height()
        if (clientHeight != nowClientHeight) {
            //键盘弹出的事件处理
            
        }
        else {
            //键盘收起的事件处理
            
        }
    })
}

//微信 通用兼容苹果、安卓自动播放语音方法
function audioPlay(id, loaded = '') {
    var voice = document.getElementById(id);
    // 调用 <audio> 元素提供的方法 play()
    if (voice.readyState > 1) {
        voice.play();
        //判断 WeixinJSBridge 是否存在
        if (typeof WeixinJSBridge == "object" && typeof WeixinJSBridge.invoke == "function") {
            voice.play();
        } else {
            //监听客户端抛出事件"WeixinJSBridgeReady"
            if (document.addEventListener) {
                document.addEventListener("WeixinJSBridgeReady", function () {
                    voice.play();
                }, false);
            } else if (document.attachEvent) {
                document.attachEvent("WeixinJSBridgeReady", function () {
                    voice.play();
                });
                document.attachEvent("onWeixinJSBridgeReady", function () {
                    voice.play();
                });
            }
        }
    } else {
        if (loaded == '') { voice.load() }
        if (voice.readyState > 1) {
            voice.play()
            //判断 WeixinJSBridge 是否存在
            if (typeof WeixinJSBridge == "object" && typeof WeixinJSBridge.invoke == "function") {
                voice.play()
            } else {
                //监听客户端抛出事件"WeixinJSBridgeReady"
                if (document.addEventListener) {
                    document.addEventListener("WeixinJSBridgeReady", function () {
                        voice.play()
                    }, false)
                } else if (document.attachEvent) {
                    document.attachEvent("WeixinJSBridgeReady", function () {
                        voice.play()
                    })
                    document.attachEvent("onWeixinJSBridgeReady", function () {
                        voice.play()
                    })
                }
            }
        } else {
            setTimeout(() => {
                audioPlay(id, 'loaded')
            }, 10);
        }
    }
}

export {
    showHideMenu, audioPlay
}